#include "front.h"
#include "lcd.h"

//0~9的模，宽度16
unsigned char w_digit[10][8*16/8] = {
	/*--  文字:  0  --*/
/*--  宋体12;  此字体下对应的点阵为：宽x高=8x16   --*/
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00,

/*--  文字:  1  --*/
/*--  宋体12;  此字体下对应的点阵为：宽x高=8x16   --*/
0x00,0x00,0x00,0x08,0x38,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00,

/*--  文字:  2  --*/
/*--  宋体12;  此字体下对应的点阵为：宽x高=8x16   --*/
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x02,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00,

/*--  文字:  3  --*/
/*--  宋体12;  此字体下对应的点阵为：宽x高=8x16   --*/
0x00,0x00,0x00,0x3C,0x42,0x42,0x02,0x04,0x18,0x04,0x02,0x42,0x42,0x3C,0x00,0x00,

/*--  文字:  4  --*/
/*--  宋体12;  此字体下对应的点阵为：宽x高=8x16   --*/
0x00,0x00,0x00,0x04,0x0C,0x0C,0x14,0x24,0x24,0x44,0x7F,0x04,0x04,0x1F,0x00,0x00,

/*--  文字:  5  --*/
/*--  宋体12;  此字体下对应的点阵为：宽x高=8x16   --*/
0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x78,0x44,0x02,0x02,0x42,0x44,0x38,0x00,0x00,

/*--  文字:  6  --*/
/*--  宋体12;  此字体下对应的点阵为：宽x高=8x16   --*/
0x00,0x00,0x00,0x18,0x24,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x22,0x1C,0x00,0x00,

/*--  文字:  7  --*/
/*--  宋体12;  此字体下对应的点阵为：宽x高=8x16   --*/
0x00,0x00,0x00,0x7E,0x42,0x04,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x00,0x00,

/*--  文字:  8  --*/
/*--  宋体12;  此字体下对应的点阵为：宽x高=8x16   --*/
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00,

/*--  文字:  9  --*/
/*--  宋体12;  此字体下对应的点阵为：宽x高=8x16   --*/
0x00,0x00,0x00,0x38,0x44,0x42,0x42,0x42,0x46,0x3A,0x02,0x02,0x24,0x18,0x00,0x00
};

/*
	draw_word:在屏幕x,y上显示高h,宽w颜色为color的字符
	@x0
	@y0
	@w
	@h
	@color
	@char s[] 
	返回值：无
*/
void draw_word(int x0,int y0,int w,int h,int color,char s[])
{
	//遍历数组的每个元素（1个字节 代表每行的8个像素素点的显示信息）
	int i,j;
	int arrary_num = w/8*h;
	
	for(i=0;i<arrary_num;i++)
	{
		//每一个数组元素的每一位代表了一个像素点 从高到低
		
		//遍历它的每一位
		for(j = 7; j>=0; j--)
		{
			/*
			判断该位是不是1
			s[i]>>j & 1 是否 >0
			1000 0000 >> 7 =>0000 0001
			0000 0001
		&	0000 0001
			0000 0001 >0
			*/
			if(s[i]>>j&1)
			{
				//在屏幕对应的位置显示即可
				lcd_draw_point(i%(w/8)*8+7-j+x0,i/(w/8)+y0,color);
			}
		}
	}
}

//在坐标为x0,y0的位置开始显示数字，数字的值为value，显示的颜色为 color
void lcd_draw_digit(int value,int x0, int y0, int color)
{
	//判断是几位数
	int sw,w,q,b,s,g;
	if(value / 100000)
	{
		sw = value/100000;
		draw_word(x0,y0,8,16,color,w_digit[sw]);
		w = value/10000%10;
		draw_word(x0+20,y0,8,16,color,w_digit[w]);
		q = value/1000%10;
		draw_word(x0+40,y0,8,16,color,w_digit[q]);
		//lcd_draw_num(q,32,100,100,RED);	
		b = value/100%10;
		draw_word(x0+60,y0,8,16,color,w_digit[b]);
		s = value/10%10;
		draw_word(x0+80,y0,8,16,color,w_digit[s]);
		g = value%10;
		draw_word(x0+100,y0,8,16,color,w_digit[g]);
	}
	else if(value / 10000)
	{
		w = value/10000;
		draw_word(x0+20,y0,8,16,color,w_digit[w]);
		q = value/1000%10;
		draw_word(x0+40,y0,8,16,color,w_digit[q]);
		//lcd_draw_num(q,32,100,100,RED);	
		b = value/100%10;
		draw_word(x0+60,y0,8,16,color,w_digit[b]);
		s = value/10%10;
		draw_word(x0+80,y0,8,16,color,w_digit[s]);
		g = value%10;
		draw_word(x0+100,y0,8,16,color,w_digit[g]);
	}
	else if (value / 1000)
	{
		q = value/1000;
		draw_word(x0+40,y0,8,16,color,w_digit[q]);
		//lcd_draw_num(q,32,100,100,RED);	
		b = value/100%10;
		draw_word(x0+60,y0,8,16,color,w_digit[b]);
		s = value/10%10;
		draw_word(x0+80,y0,8,16,color,w_digit[s]);
		g = value%10;
		draw_word(x0+100,y0,8,16,color,w_digit[g]);
	}
	else if (value / 100)
	{
		b = value/100;
		draw_word(x0+60,y0,8,16,color,w_digit[b]);
		s = value/10%10;
		draw_word(x0+80,y0,8,16,color,w_digit[s]);
		g = value%10;
		draw_word(x0+100,y0,8,16,color,w_digit[g]);	
	}
	else if (value / 10)
	{
		s = value/10;
		draw_word(x0+80,y0,8,16,color,w_digit[s]);
		g = value%10;
		draw_word(x0+100,y0,8,16,color,w_digit[g]);
	}
	else 
	{
		draw_word(x0+100,y0,8,16,color,w_digit[value]);
	}
}
	